package ru.spb.osll.myfit.client.widget;

import static org.easymock.EasyMock.anyBoolean;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.isA;

import org.easymock.EasyMockSupport;
import org.junit.AfterClass;
import org.junit.BeforeClass;

import ru.spb.osll.myfit.client.widget.TableWidget.MyFlexTable;

import com.google.gwt.junit.GWTMockUtilities;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class ClientTestCase extends EasyMockSupport {
	public GWTWidgetFactory gwtWidgetFactory;

	public PopupPanel popupPanel;
	public MenuBar menuBar;
	public MenuItem menuItem;
	public FlexTable flexTable;
	public VerticalPanel verticalPanel;
	public ScrollPanel scrollPanel;
	public Composite disclosurePanel;
	public DecoratorPanel decoratorPanel;
	public MyFlexTable myFlexTable;

	@BeforeClass
	public static void disarmGWT() {
		GWTMockUtilities.disarm();
	}

	@AfterClass
	public static void restoreGWT() {
		GWTMockUtilities.restore();
	}
	
	public void setUpGWTStubs() {
		gwtWidgetFactory = createMock(GWTWidgetFactory.class);

		popupPanel = createNiceMock(PopupPanel.class);
		menuBar = createNiceMock(MenuBar.class);
		menuItem = createNiceMock(MenuItem.class);
		flexTable = createNiceMock(FlexTable.class);
		verticalPanel = createNiceMock(VerticalPanel.class);
		scrollPanel = createNiceMock(ScrollPanel.class);
		disclosurePanel = createNiceMock(Composite.class);
		decoratorPanel = createNiceMock(DecoratorPanel.class);
		myFlexTable = createNiceMock(MyFlexTable.class);

		expect(gwtWidgetFactory.createPopupPanel()).andReturn(popupPanel).anyTimes();
		expect(gwtWidgetFactory.createMenuBar()).andReturn(menuBar).anyTimes();
		expect(
				gwtWidgetFactory.createMenuItem(isA(String.class),
						anyBoolean(), isA(Command.class))).andReturn(menuItem)
				.anyTimes();
		expect(gwtWidgetFactory.createFlexTable()).andReturn(flexTable)
				.anyTimes();
		expect(gwtWidgetFactory.createVerticalPanel()).andReturn(verticalPanel)
				.anyTimes();
		expect(gwtWidgetFactory.createScrollPanel()).andReturn(scrollPanel)
				.anyTimes();
		expect(
				gwtWidgetFactory.createDisclosurePanel(isA(String.class),
						isA(Widget.class))).andReturn(disclosurePanel)
				.anyTimes();
		expect(gwtWidgetFactory.createDecoratorPanel()).andReturn(
				decoratorPanel).anyTimes();
		expect(gwtWidgetFactory.createMyFlexTable()).andReturn(myFlexTable)
				.anyTimes();
	}
}
